<?php

// Get the access token with app_id and app_secret
$url1 = 'https://graph.facebook.com/oauth/access_token';
$data1 = array('client_id' => '334619919999877',
	'client_secret'=>'ec96fb04e9c2ae9782718e1a4cfbc946',
	'grant_type'=>'client_credentials'
);
$getAccessTokenResult = explode('=',curlUsingGet($url1, $data1));
$access_token = $getAccessTokenResult['1'];


// Get the posts
$url2 = 'https://graph.facebook.com/SmartekConsultancy';
$data2 = array(
'fields'=>'posts.limit(5)',
'access_token'=>$access_token
);


// Print the result array
print_r(curlUsingGet($url2, $data2));


$result = curlUsingGet($url2, $data2);

function curlUsingGet($url, $data)
{

    if(empty($url))
    {
        return 'Error: invalid Url or Data';
    }

	//url-ify the data for the POST
	$fields_string = '';
	foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
	$fields_string = rtrim($fields_string,'&');


	//open connection
	$ch = curl_init();
	$url = $url."?".$fields_string;
	echo "<br>url to hit".$url."</br><br>";


	curl_setopt($ch,CURLOPT_URL,$url);


	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); # timeout after 10 seconds, you can increase it
	//curl_setopt($ch,CURLOPT_HEADER,false);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  # Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); # Some server may refuse your request if you dont pass user agent

	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

	//execute post
	$result = curl_exec($ch);

	//close connection
	curl_close($ch);
	return $result;
}